﻿using System;
using System.Collections.Generic;

using System.Text;
using NHibernate;
using OpenGado.DATA.Entities;

namespace OpenGado.DATA
{
    public class ProductPriceDataControl
    {

        private static ProductPriceDataControl productPriceDataControl;
        private static object lockPriceDataControl = new object();
        private ISession session;

        public ISession Session
        {
            get
            {
                if (session == null)
                {
                    session = FactoryHandler.CreateFactory().OpenSession();

                }

                return session;
            }
        }

        public static ProductPriceDataControl Instance
        {
            get
            {
                lock(lockPriceDataControl)
                    if(productPriceDataControl == null)
                    {

                        productPriceDataControl = new ProductPriceDataControl();
                    }
                return productPriceDataControl;
            }

        }


        public void Save(ProductPriceHistory priceHistoryItem)
        {
            this.Session.SaveOrUpdate(priceHistoryItem);
        }

        public ProductPriceHistory GetByid(int priceHistoryItemId)
        {

         return   this.Session.Get<ProductPriceHistory>(priceHistoryItemId);
        }


        public IList<ProductPriceHistory> GetProductPriceHistory()
        {
            ICriteria criteria = Session.CreateCriteria<ProductPriceHistory>();
            IList<ProductPriceHistory> productPriceHistory = criteria.List<ProductPriceHistory>();

            return productPriceHistory;
        }
    }
}
